<template>
  <div class="login">
    <div class="main">
      <el-form :model="user" ref="user" label-width="auto">
        <el-form-item
          prop="username"
          :rules="[
            { required: true, message: '请输入用户名', trigger: 'blur' },
            {
              message: '用户名长度必须为2-11位',
              trigger: ['blur', 'change'],
              pattern: /^.{2,11}$/,
            },
          ]"
        >
          <el-input
            v-model="user.loginName"
            prefix-icon="el-icon-mobile-phone"
            placeholder="请输入用户名"
          ></el-input>
        </el-form-item>
        <el-form-item
          prop="password"
          :rules="[
            {
              required: true,
              message: '请输入密码',
              trigger: 'blur',
            },
            {
              message: '密码长度不能小于5位',
              trigger: ['blur', 'change'],
              pattern: /^.{5,}$/,
            },
          ]"
        >
          <el-input
            v-model="user.password"
            prefix-icon="el-icon-lock"
            placeholder="请输入密码"
          ></el-input>
        </el-form-item>
        <el-form-item class="btn" style="width: 100%">
          <el-button type="primary" @click="submitForm('user')">登录</el-button>
        </el-form-item>
      </el-form>
      <div class="logo">
        <img src="../assets/img/logo.595745bd.png" alt="" />
      </div>
      <img :src="url" alt="" style="width: 100px; height: 100px" />
    </div>
  </div>
</template>
<script>
import { getCodePic } from "@/api/user";
export default {
  name: "LoginPage",
  data() {
    return {
      url: "https://likede2-java.itheima.net/api/user-service/user/imageCode/G3nYzIYKCrvxgGc2T3UsizHAkLYXv7xR",
      user: {
        loginName: "demo",
        password: "888itcast.CN764%...",
        mobile: "",
        code: "",
        clientToken: "data:image/JPEG;base64,",
        loginType: "0",
        account: "",
      },
    };
  },
  async created() {
    const res = await getCodePic();
    console.log(res);
    // this.user.clientToken += res.data;
    // this.url=res.data
    // const binaryData =res.data
    // // const blob = new Blob([binaryData], {type: 'image/jpeg'})
    // const file = new File([binaryData], 'photo.jpg', {type: 'image/jpeg'})
    // const url = URL.createObjectURL(file) // 创建URL
    // this.url=url
    // console.log(this.user.clientToken);
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$message.success("登录成功");
        }
      });
    },
  },
};
</script>
<style lang='less'  scoped>
.login {
  width: 100vw;
  height: 100vh;
  background-image: url("../assets/img/background.be4fae7d.png");
  position: relative;
  .main {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 518px;
    height: 450px;
    background-color: #fff;
    border-radius: 10px;
    .el-form {
      width: 100%;
      margin-top: 114px;
      margin-bottom: 22px;
      padding: 0 20px;
      .btn {
        display: flex;
        justify-content: flex-end;
      }
    }
    .logo {
      width: 140px;
      height: 140px;
      position: absolute;
      top: 0;
      left: 50%;
      transform: translate(-50%, -50%);
      border-radius: 50%;
      background-color: #eee;
      box-shadow: 5px 5px 5px #ccc;
      img {
        width: 100%;
        height: 100%;
        border-radius: 50%;
      }
    }
  }
}
</style>
